package d.f;

import d.h.b.c;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;

class q extends p {
    public static <T> T a(Iterable<? extends T> iterable) {
        c.c(iterable, "$this$single");
        if (iterable instanceof List) {
            return b((List) iterable);
        }
        Iterator<? extends T> it = iterable.iterator();
        if (it.hasNext()) {
            T next = it.next();
            if (!it.hasNext()) {
                return next;
            }
            throw new IllegalArgumentException("Collection has more than one element.");
        }
        throw new NoSuchElementException("Collection is empty.");
    }

    public static final <T> T b(List<? extends T> list) {
        c.c(list, "$this$single");
        int size = list.size();
        if (size == 0) {
            throw new NoSuchElementException("List is empty.");
        } else if (size == 1) {
            return list.get(0);
        } else {
            throw new IllegalArgumentException("List has more than one element.");
        }
    }
}
